<?php
namespace app\api\controller;
use think\console\Table;
use think\Controller;
use think\Db;

/**
 * 栏目
 * */
class Home extends Base
{
    // 2019/10/8日 还未做，先做表单提交
    //首页banner图
    public function Banner($id){
        $arr=[
            'is_show'   =>1,
            'navigation_id'  =>$id
        ];
        $data=[];
        $info=Db::name('banner')->where($arr)->field('id,head_img')->select();
        if($info){
            foreach ($info as $value){
                $value['head_imgUrl']=$this->getDomain(false).$value['head_img'];
                $data[]=$value;
            }
        }
        return $this->datas($data);
    }

    //表单提交内容接收  已经完成，不需更改
    public function postInfo(){
        if(empty(input('name'))|| empty(input('phone') )){

            return $this->return_error([],0,'预约失败');
        }
        $info['name']=input('name')?input('name'):'';
        $info['phone']=input('phone')?input('phone'):'';
        $info['province']=input('province')?input('province'):'';
        $info['city']=input('city')?input('city'):'';
        $info['county']=input('county')?input('county'):'';
        $info['detail']=input('detail')?input('detail'):'';
        $info['sex']=input('sex')?input('sex'):'';
        $info['day']=input('day')?input('day'):'';
        $info['qq']=input('qq')?input('qq'):'';
        $info['email']=input('email')?input('email'):'';
        $info['weixin']=input('weixin')?input('weixin'):'';
        $info['investment']=input('investment')?input('investment'):'';
        $info['text']=input('text')?input('text'):'';
        if(!empty($info['province'])){
            $province=Db::name("base_province")->where('code',$info['province'])->find();
            $info['province']=$province['name'];
        }
        if(!empty($info['city'])){
            $city=Db::name("base_city")->where('code',$info['city'])->find();
            $info['city']=$city['name'];
        }
        if(!empty($info['county'])){
            $county=Db::name("base_area")->where('code',$info['county'])->find();
            $info['county']=$county['name'];
        }
        $data=Db::name("public")->insert($info);
        if($data){
            return  $this->return_success($data,'200','提交成功');
        } else{
            return  $this->return_error($data,0,'预约失败');
        }
    }
    public function postProvince(){
        $info=Db::name('base_province')->select();
        return $this->datas($info);
    }
    public function postCity($code){
        $info=Db::name('base_city')->where('province_code',$code)->select();
        return $this->datas($info);
    }
    public function postArea($code){
        $info=Db::name('base_area')->where('city_code',$code)->select();
        return $this->datas($info);
    }
}

